package com.itheima.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.LocalDateTime;

/**
 * 删除
 */
public class JdbcDemo4 {
    public static void main(String[] args) throws Exception{
        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver") ;

            //获取连接对象
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tlias", "root", "204020");
            //sql
            String sql = "select * from dept";
            //执行对象
            statement = connection.createStatement();
            //执行sql
            ResultSet resultSet = statement.executeQuery(sql);
            //处理结果
            while(resultSet.next()) {
                String name = resultSet.getString("name") ;
                LocalDateTime createTime = resultSet.getTimestamp("create_time").toLocalDateTime() ;
                LocalDateTime updateTime = resultSet.getTimestamp("update_time").toLocalDateTime() ;

                System.out.println(name + " " + createTime + " " + updateTime);
            }

        } finally {
            //释放资源
            statement.close();
            connection.close();
        }
    }
}
